package com.michael.study.customview.animation

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.animation.AnimationUtils
import com.michael.study.customview.R
import com.michael.study.customview.databinding.ActivityXmlAnimatinBinding

class XmlAnimationActivity : AppCompatActivity(), View.OnClickListener {

    private lateinit var mBinding:ActivityXmlAnimatinBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivityXmlAnimatinBinding.inflate(layoutInflater)
        setContentView(mBinding.root)
        mBinding.btnScale.setOnClickListener(this)
        mBinding.btnAlpha.setOnClickListener(this)
        mBinding.btnTranslate.setOnClickListener(this)
        mBinding.btnRotate.setOnClickListener(this)
        mBinding.btnSet.setOnClickListener(this)

    }

    override fun onClick(v: View?) {
        when(v?.id) {
            R.id.btn_scale -> {
                doScale()
            }
            R.id.btn_alpha -> {
                doAlpha()
            }
            R.id.btn_translate -> {
                doTranslate()
            }
            R.id.btn_rotate -> {
                doRotate()
            }
            R.id.btn_set -> {
                doSet()
            }
        }
    }

    private fun doScale() {
        var animation = AnimationUtils.loadAnimation(this,R.anim.scale_test)
        mBinding.view.startAnimation(animation)
    }

    private fun doAlpha() {
        var animation = AnimationUtils.loadAnimation(this,R.anim.alpha_test)
        mBinding.view.startAnimation(animation)
    }

    private fun doTranslate() {
        var animation = AnimationUtils.loadAnimation(this,R.anim.translate_test)
        mBinding.view.startAnimation(animation)
    }

    private fun doRotate() {
        var animation = AnimationUtils.loadAnimation(this,R.anim.rotate_test)
        mBinding.view.startAnimation(animation)
    }

    private fun doSet() {
        var animation = AnimationUtils.loadAnimation(this,R.anim.set_test)
        mBinding.view.startAnimation(animation)
    }
}